package com.zjw.service.impl;

import com.zjw.annotation.domain.entity.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;


@Data
@AllArgsConstructor
@NoArgsConstructor
public class LoginUser implements UserDetails {

    private User user;

//    角色以"ROLE_"开头  例如： ROLE_Admin ROLE_Link
//    权限为权限代码      例如： sys:link:save
    private List<String> myAuthorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
//        因为使用自定义的权限校验规则和方法，所以可以不采用Security默认的权限封装和获取
        return null;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUserName();

    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
